﻿// 1.1.7.03. Write a program, which compares two arrays of type char lexicographically (character by character) and
// checks, which one is first in the lexicographical order.

using System;

class SortByLexicographicalOrder
{
    static void Main()
    {
        char[] firstCharArray = new char[] { 'a', 'b', 'c', 'd' };
        char[] secondCharArray = new char[] { 'a', 'b', 'c' };
        bool firstArrayIsShorter = true;
        bool arraysEqualLength = false;
        byte shortestArrayLength = (byte)firstCharArray.Length;
        if (firstCharArray.Length > secondCharArray.Length)
        {
            shortestArrayLength = (byte)secondCharArray.Length;
            firstArrayIsShorter = false;
        }
        else if (firstCharArray.Length == secondCharArray.Length)
        {
            arraysEqualLength = true;
        }


        for (int i = 0; i < shortestArrayLength; i++)
        {
            if (firstCharArray[i] < secondCharArray[i])
            {
                Console.WriteLine("The first array has earlier lexicographical order.");
                break;
            }
            else if (firstCharArray[i] > secondCharArray[i])
            {
                Console.WriteLine("The second array has earlier lexicographical order.");
                break;
            }

            if (i == (shortestArrayLength - 1))
            {
                if (firstArrayIsShorter == true && arraysEqualLength == false)
                {
                    Console.WriteLine("The first array has earlier lexicographical order.");
                    break;
                }
                else if (firstArrayIsShorter == false && arraysEqualLength == false)
                {
                    Console.WriteLine("The second array has earlier lexicographical order.");
                    break;
                }
                else
                {
                    Console.WriteLine("Both arrays have equal lexicographical order.");
                }
            }
        }
    }
}